<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Grouping</title>

<link rel="stylesheet" href="styles/kendo.common.min.css" />
<link rel="stylesheet" href="styles/kendo.default.min.css" />
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/kendo.all.min.js"></script>


</head>

<body>
<div id="grid"></div>
<script type="text/x-kendo-template" id="template">

    <div class="subgrid"></div>

</script>
<script type="text/javascript">
	var CongTrinh = 4;
	
	//
	//
	var modelHangMucCongViec = kendo.data.Model.define({
		id: "CVid",
		fields: {
			MaCV: {type: "string",},
			TenCV: {type: "string",},
			DVT: {type: "string",},
			KhoiLuong: {type: "number",},
			TenHM: {type: "string",},
			
		},
		
	});
	//
	//
	var modelDinhMuc = kendo.data.Model.define({
		id: "cid",
		fields: {
			cid: {
				type: "number",
			},
			MHDM: {
				type: "string",	
			},
			TenCV: {
				type: "string",	
			},
			DVT: {
				type: "string",	
			},	
		},
		
	});
	//
	var modelCongTrinh = kendo.data.Model.define({
		id: "CTid",
		fields:{
			"CTid": {
				type: "number",	
				editable: false,
			},
			"TenCT": {
				type: "string",
				validation: { required: true},
			},	
			"Khac": {
				type: "string",	
			}
			
		},
			
	});
//
//
	var modelPhanTichVatTu = kendo.data.Model.define ({
		id: "DMid",
		field: {
			MaVT: {
				type: "string",
				},
			TenVT:{
				type: "string",
				},						
			DVT: {
				type: "string",
				},
			GiaGoc:{
				type: "number",
				},
			HaoPhiVatTu:{
				type: "number",
				},
			Loai: {
				type: "string",
				},
			TenLoai: {
				type: "string",
				},			
		}
	});
	//
	//
	var modelProduct = kendo.data.Model.define ({
		id: "ProductID",
		field: {
			ProductID:{
				type: "number",	
			},
			ProductName:{
				type: "string",	
			},
			SupplierID:	{
				type: "number",	
			},
		}
		
	});
	//
	//
	var modelHangMuc = new kendo.data.Model.define({
		id: "HMid",
		fields: {
			
			"HMid": { 
				type: "number",
				editable: false,		
			},
			TenHM: {
				type: "string",	
				validation: {	
					required: true,
				}
			},		
			MaCT:	{
				type: "number",	
				editable: false,
				defaultValue: CongTrinh,
			},
			Khac: {
				type: "string",	
			}
			
		},
		
	});
	//
	//
	
	//
	//
	var dataHangMucCongViec = new kendo.data.DataSource({
		transport: {
			read: "data/hangmuccongviec.php",	
		},
		
		schema: {
			data: "data",
			model: modelHangMucCongViec,
		},
		
		group: {
			field: "TenHM", aggregates: [
									
			]
		},

		aggregate: [ ]
		
	});
	var dataHangMuc = new kendo.data.DataSource({		
		transport: {
			read: "dutoan/hangmuc/fetch.php?congtrinh=4",
			update:{
				url: "dutoan/hangmuc/update.php",
				type: "POST",
					
			},
			create: {
				url: "dutoan/hangmuc/create.php",
				type: "POST",	 
			},
			destroy: {
				url: "dutoan/hangmuc/destroy.php",
				type: "POST",
			},
		},
		
		schema: {
			data: "data",
			model: modelHangMuc,
		},
		editalbe: true,

		//serverFiltering: true,
		//filter: { field: "MaCT", operator: "eq", value:$("#danhsachcongtrinh").val() },
   
	
	});	
	//
	//
	var dataPhanTichVatTu = kendo.data.Model.define ({

		transport: {
			read: "data/phantichvattu.php",	
		},
		schema: {
			data: "data",
			model: modelPhanTichVatTu,
		},
		
		group: {
			field: "TenLoai", aggregates: [
				
			]
		},

		aggregate: [ ],
			
		
	});
	//
	//
	$(document).ready(function() {
		$("#grid").kendoGrid({
              	dataSource: dataHangMucCongViec,
					
				columns: [
					{field: "MaCV", title: "Ma Công Việc"},
					{field: "TenCV", title: "Ten Công Việc"},
					{field: "DVT", title: "DVT"},
					{field: "KhoiLuong", title: "Khối Lượng"},
					//{field: "MaCV", title: "Ma CV"},
				
				],
				
				detailTemplate: kendo.template($("#template").html()),
    			detailInit: detailInit
				
	});
	
	function detailInit(e) {
    // get a reference to the current row being initialized 
		var detailRow = e.detailRow;
	
		// create a subgrid for the current detail row, getting territory data for this employee
	
		detailRow.find(".subgrid").kendoGrid({
			dataSource: {
				transport: {
					read: "data/phantichvattu.php",//?congviec=" + (e.data.MaCV),	
				},
				schema: {
					data: "data",
					model: modelPhanTichVatTu,
				},
				
				group: {
							field: "TenLoai", aggregates: [
								
							]
				},

				aggregate: [ ],
				
				serverFiltering: true,
				filter: { field: "MaCV", operator: "eq", value:e.data.MaCV },
			},
				
			columns:[
				{field: "MaVT", title: "Mã Vật Tư"},
				{field: "TenVT", title: "Tên Vật Tư"},
				{field: "DVT", title: "DVT"},
				{field: "GiaGoc", title: "Giá Gốc"},
				{field: "HaoPhiVatTu", title: "Hao Phí Vật Tư"},
				//{field: "TenLoai", title: "Loại Vật Tư"}, 
			
			],
			
			
	
		});
	}
		
		$("#grid_").kendoGrid({
              	dataSource: {
					transport: {
						read: "data/phantichvattu.php",	
					},
					schema: {
						data: "data",
						model: modelPhanTichVatTu,
					},
					
					group: {
							 	field: "TenLoai", aggregates: [
									
							 	]
					},

					aggregate: [ ]
				},
				
				columns:[
					{field: "MaVT", title: "Mã VT"},
					{field: "TenVT", title: "Tên VT"},
					{field: "DVT", title: "DVT"},
					{field: "GiaGoc", title: "Giá Gốc"},
					{field: "HaoPhiVatTu", title: "Hao Phi Vat Tu"},
					//{field: "TenLoai", title: "Loại Vật Tư"}, 
				
				],
			  
			  
	});
		$("#grid_").kendoGrid({
			dataSource: {
				//type: "odata",
				transport: {
					read: "data/products.php"
				},
				
				schema:{
					data: "data",
					model: modelProduct,
				},
				
				//pageSize: 7,
				group: {
						 field: "SupplierID", aggregates: [
							{ field: "ProductName", aggregate: "count" },
							{ field: "ProductID", aggregate: "count"},
						 ]
					   },

				aggregate: [ { field: "ProductName", aggregate: "count" },
							  { field: "ProductID", aggregate: "count"},]                            
			},
			sortable: true,
			scrollable: false,
			//pageable: true,
			columns: [
				{ field: "ProductName", title: "Product Name", footerTemplate: "Total Count: #=count#", groupFooterTemplate: "Count: #=count#" },
				{ field: "ProductID", title: "ProductID" },
				{ field: "SupplierID", title: "Supplier"},
			]
		});
});

</script>
</body>
</html>
